<?php

function createZendRow($tableName, $params, $outputFileName) {
    $className = "Application_Model_Rows_" . ucfirst($tableName);

    $class = "class " . $className . " extends Zend_Db_Table_Row_Abstract {\n";

    $class .= "    public __Construct(\$params) {\n";
    $class .= "        foreach(\$params as \$pname => \$pvalue) {\n";
    $class .= "            \$this->__set(\$pname,\$pvalue)";
    $class .= "        }\n";
    $class .= "    }\n";

    $class .= "    public function __set(\$name, \$value) {";
    $class .= "        \$method = 'set' . ucfirst(\$name);";
    $class .= "        if (('mapper' == \$name) || !method_exists(\$this, \$method)) {";
    $class .= "            throw new Exception('Invalid " . $className . " property');";
    $class .= "        }";
    $class .= "        \$this->\$method(\$value);";
    $class .= "    }\n";

    $class .= "public function  __get(\$name) {
        \$method = 'set' . ucfirst(\$name);
        if (('mapper' == \$name) || !method_exists(\$this, \$method)) {
            throw new Exception('Invalid User property');
        }
        return \$this->\$method();
      }\n";

    foreach ($params as $pname) {
        $class .= "    private " . $pname . ";\n";
    }
    foreach ($params as $pname) {
        $class .= "    public get" . ucfirst($pname) . "() {\n";
        $class .= "        return \$this->" . $pname . ";\n";
        $class .= "    }\n";
    }
    foreach ($params as $pname) {
        $class .= "    public set" . ucfirst($pname) . "(\$" . $pname . ") {\n";
        $class .= "        \$this->" . $pname . " = \$" . $pname . ";\n";
        $class .= "    }\n";
    }
    $class .= "}";
    if (file_exists($outputFilePath))
        unlink($outputfile);

    $fileHandle = fopen($outputFilePath, 'w') or die("can't open file");
    fwrite($fileHandle, '<?php' . $class);
    fclose($fileHandle);
}

?>
